from collections import defaultdict
from typing import List

"""思路
枚举，模拟过程，使用哈希表记录，是否访问过
"""
class Solution:
    def calculateScore(self, instructions: List[str], values: List[int]) -> int:
        ans = 0
        n = len(instructions)
        i = 0
        has = defaultdict(int)
        while i < n and i >= 0:
            if has[i] == 1:
                break
            has[i] = 1
            if instructions[i] == "add":
                ans += values[i]
                i += 1
            else:
                if instructions[i] == "jump":
                    i += values[i]

        return ans
